from sqlite3 import Date

from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.forms import inlineformset_factory

from customauth.models import MyUser

from .models import (
    Spr_lpu,
    Spr_sdl,
)


class DateInput(forms.DateInput):
    input_type = "date"
    format = "%d.%m.%Y"
    attrs = {
        "class": "form-control",
        "placeholder": "Select a date",
        "type": "date",  # <--- IF I REMOVE THIS LINE, THE INITIAL VALUE IS DISPLAYED
    }


# Float field
class FloatInput(forms.NumberInput):
    input_type = "number"
    attrs = {
        "class": "form-control",
        "placeholder": "Enter a number",
        "type": "number",
        "step": "0.01",
    }


class TextInput(forms.TextInput):
    input_type = "text"
    attrs = {"class": "form-control", "placeholder": "Введите текст", "style": "width: 100%"}


# class ImageForm(forms.ModelForm):
#     class Meta:
#         model = Images
#         fields = "__all__"
#         widgets = {
#             "etap": forms.HiddenInput(),
#             "img": forms.ImageField(widget=forms.FileInput()),
#         }


class NumberInput(forms.NumberInput):
    input_type = "number"
    attrs = {
        "class": "form-control",
        "placeholder": "Введите число",
        "style": "width: 100%",
    }


# class WorkerForm(forms.ModelForm):
#     class Meta:
#         model = Worker
#         fields = ("uid", "fam", "im", "ot", "dr", "adress", "dred")
#         widgets = {
#             "dr": DateInput(),
#             "dred": DateInput(),
#         }
#         readonly_fields = ("dred",)
#         labels = {
#             "uid": "Номер карты",
#             "fam": "Фамилия",
#             "im": "Имя",
#             "ot": "Отчество",
#             "dr": "Дата рождения",
#             "adress": "Адрес",
#             "dred": "Дата редактирования",
#         }
#         error_messages = {
#             "uid": {
#                 "max_length": "Максимальная длина поля 7 символов",
#                 "min_length": "Минимальная длина поля 1 символ",
#                 "required": "Поле обязательно для заполнения",
#             }
#         }


# class Pl_uslp(forms.ModelForm):
#     class Meta:
#         model = Pl_uslp
#         fields = (
#             "idkv",
#             "kusl",
#             "usl",
#             "kol",
#             "price",
#             "stu",
#         )


# class NaryadForm(forms.ModelForm):
#     def __init__(self, *args, **kwargs):
#         super(NaryadForm, self).__init__(*args, **kwargs)

#         self.fields["sdl_etap"].queryset = Spr_sdl.objects.filter(sdl__in=[1, 35, 36, 37, 3500])
#         self.fields["lpu"].queryset = Spr_lpu.objects.all()
#         self.fields["patient"].queryset = Patient.objects.all()

#     class Meta:
#         model = It_lab
#         fields = (
#             "idkv",
#             "nkv",
#             "dou",
#             "dzr",
#             "pdzr",
#             "check_zav",
#             "check_tech",
#             "stu",
#             "opl",
#             "sris",
#             "dnaz_etap",
#             "dn_etap",
#             "sdl_etap",
#             "id_etap",
#             "dz_etap",
#             "user_etap",
#             "mpp_etap",
#             "kom_etap",
#             "id_last",
#             "sdl_set",
#             "lpu",
#             "naryad_doc",
#             "container",
#         )
#         widgets = {
#             "idkv": NumberInput(),
#         }
#         readonly_fields = (
#             "id_etap",
#             "idkv",
#             "nkv",
#             "dou",
#             "stu",
#             "opl",
#             "dnaz_etap",
#             "dn_etap",
#             "sdl_etap",
#             "id_etap",
#             "dz_etap",
#             "user_etap",
#             "mpp_etap",
#         )
#         labels = {
#             "idkv": "Код квитанции",
#             "nkv": "Номер квитанции",
#             "dou": "Дата оформления",
#             "dzr": "Дата закрытия",
#             "stu": "Стоимость",
#             "opl": "Оплата",
#             "sris": "Срок исполнения",
#             "dnaz_etap": "Дата назначения этапа",
#             "dn_etap": "Дата начала этапа",
#             "sdl_etap": "Специальность этапа",
#             "id_etap": "Номер этапа",
#             "dz_etap": "Дата закрытия этапа",
#             "user_etap": "Исполнитель этапа AD",
#             "mpp_etap": "МПП этапа",
#             "kom_etap": "Комментарий этапа",
#             "id_last": "ИД последнего этапа",
#             "sdl_set": "Набор специалистов",
#             "lpu": "ЛПУ",
#             "naryad_doc": "Доктор",
#         }


# class NaryadFullForm(NaryadForm):
#     images = forms.FileField(widget=forms.ClearableFileInput(), required=False)

#     class Meta(NaryadForm.Meta):
#         fields = NaryadForm.Meta.fields + (
#             "lpu",
#             "patient",
#             "images",
#             "id_last",
#             "sdl_set",
#             "naryad_doc",
#             "user_etap_link",
#             "container",
#         )


class SignUpForm(UserCreationForm):
    class Meta:
        model = MyUser
        exclude = (
            "id",
            "is_active",
            "is_staff",
            "is_admin",
            "is_superuser",
            "last_login",
            "date_joined",
            "groups",
            "user_permissions",
            "id_password",
        )
